<?php
    include('session.inc');
    ob_start();
    include 'color_style.php';
    require '../plugins/input/classInput.inc.php';
    require '../plugins/users/classUsersData.inc.php';
    require_once('OpenDB.inc');
    
    include LANGUAGE;

    if (!OpenDB()) break;

    $_Input = new classInput();

    $A_Nick=trim($_Input->Sterilize($_REQUEST["A_Nick"]));
    $A_Passwd=trim($_Input->Sterilize($_REQUEST["A_Passwd"]));
    $PcoductExist=$_REQUEST["PcoductExist"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>METIS Admin</title>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET_;?>">
    <?php include 'html_style.php'; ?>
</head>
<body bgcolor="<?php echo Background_Color; ?>">
    <center>
        <h2><b><?php echo I_TITULOK;?></b></h2>
    </center>
    <br />
    <center>
        <table CellPadding="5" style="border:3px solid #9C8A88;" bgcolor="<?php echo BACKGROUND_IN_TABLE;?>">
            <tr>
                <td>
                    <img src="img/home_screen/home.png" alt="METIS ADMIN" />
                </td>
                <td>

<?php
    if ($A_Nick=="")
        print"
            <form name=\"SQL\" action=\"index.php\" method=\"post\">
                <table CellPadding=\"5\" style=\"width:300px;\" bgcolor=\"".BACKGROUND_IN_TABLE."\">
                    <tr>
                        <td align=\"left\">
                            <b>".I_NICK.": </b>
                        </td>
                        <td>
                            <input type=\"text\" name=\"A_Nick\" value=\"\">
                        </td>
                    </tr>
                    <tr>
                        <td align=\"left\">
                            <b>".I_HESLO.": </b>
                        </td>
                        <td>
                            <input type=\"password\" name=\"A_Passwd\" value=\"\" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan=\"2\">
                            <input type=\"submit\" value=\"".I_LOGIN."\" style=\"width :300px; background-color: ".BUTTON_ON_OUT.";\"
                                onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\"
                                onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                            />
                        </td>
                    </tr>
                </table>
            </form>";
    else
    {
        do
        {
            

            $sql_sel= "SELECT * FROM admins WHERE (A_Nick='".$A_Nick."' AND A_Passwd='".sha1($A_Passwd)."')";
            $volum = mysql_query($sql_sel);
            $AdmFound=0;
            while($sql_array = mysql_fetch_object($volum))
            {
                if($sql_array->A_Nick==$A_Nick && $sql_array->A_Passwd==sha1($A_Passwd))
                {

                    $_UD = new classUsersData();
                    $_UD->ForgottenPasswd_DeleteAllExpiredNewPassword();

                    $AdmFound=1;
                    $a=$sql_array->ID;
                    $_SESSION['admin']=$a;
                    $_SESSION['rights']=$sql_array->A_Rights;
                    header('Location:main.php');
                }
            }
            if($AdmFound==0)
                print"
                    <form name=\"SQL\" action=\"index.php\" method=\"post\">
                        <table CellPadding=\"5\" style=\"width:300px;\" bgcolor=\"".BACKGROUND_IN_TABLE."\">
                            <tr>
                                <td align=\"left\">
                                    <b>".I_NICK.": </b>
                                </td>
                                <td>
                                    <input type=\"text\" name=\"A_Nick\" value=\"\">
                                </td>
                            </tr>
                            <tr>
                                <td align=\"left\">
                                    <b>".I_HESLO.": </b>
                                </td>
                                <td>
                                    <input type=\"password\" name=\"A_Passwd\" value=\"\" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan=\"2\">
                                    <font style=\"font-size:10px; font-family:verdana; color:red;\"><b>".I_LOGIN_ERR."</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td colspan=\"2\">
                                    <input type=\"submit\" value=\"".I_LOGIN."\" style=\"width :300px; background-color: ".BUTTON_ON_OUT.";\"
                                        onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\"
                                        onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                                    />
                                </td>
                            </tr>
                        </table>
                    </form>";
        }
        while (false);
        mysql_close();
    }
?>                
            </td>
        </tr>
    </table>
    <center><a href="../"> <?php echo I_PREJST_DO_OBCHODU; ?> </a></center>
    <img src="admin.jpg" align="top" style="position:relative;left:0px;top:80px;" alt="METIS ADMIN" />
    </center>
</body>
</html>
